<?php
$StudentId = $_GET['StudentId']??'';
//echo $StudentId;

// 连接数据库
$dsn = "sqlsrv:Server=LAPTOP-G184I03M\SQLEXPRESS;Database=Student";
$db = new PDO($dsn, "sa", "123456");
$sql = "select * from Student where StudentId='{$StudentId}'";
$statement = $db->query($sql);
$result = $statement->fetch(PDO::FETCH_ASSOC);
//var_dump($db->errorInfo()); // 排查数据库错误。
//var_dump($result);
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改学生信息</title>
    <link rel="stylesheet" type="text/css" href="css/main.css" />
</head>
<body>
<div id="container">
    <form method="post" action="student_update_save.php">
        <table class="update">
            <caption>
                <h3>修改学生信息</h3>
            </caption>
            <tr>
                <td>学生id：</td>
                <td><input type="text" name="StudentId" value="<?php echo $result['StudentId']?>"/></td>
            </tr>
            <tr>
                <td>学生姓名：</td>
                <td><input type="text" name="StudentName" value="<?php echo $result['StudentName']?>"/></td>
            </tr>
            <tr>
                <td>学生性别：</td>
                <td>
                    <input type="radio" name="StudentSex" value="1" <?php if($result['StudentSex'] ==1){
                        echo 'checked = "checked"';
                    }?>/> 男
                    <input type="radio" name="StudentSex" value="2" <?php if($result['StudentSex'] ==2){
                        echo 'checked = "checked"';
                    }?>/> 女
                </td>
            </tr>
            <tr>
                <td>学生生日：</td>
                <td><input type="text" name="StudentBirth" value="<?php echo $result['StudentBirth']?>"/></td>
            </tr>
            <tr>
                <td>学生住址：</td>
                <td><input type="text" name="StudentAddress" value="<?php echo $result['StudentAddress']?>"/></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" value="提交" class="btn" />
                    <input type="reset" value="重置" class="btn" />
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>